/*
 * @Author: qinuoyun
 * @Date:   2019-11-08 18:45:28
 * @Last Modified by:   sean
 * @Last Modified time: 2019-12-27 15:30:35
 * 这是一个非常重要的文件 反向实例化的时候需要
 */
import md5 from 'js-md5';
import Vue from 'vue'

function ltrim(str, value = " ") {
  let leng = value.length;
  let init = str.slice(0, leng);
  if (init == value) {
    return str.slice(leng);
  } else {
    return str;
  }
}

const modulesFiles = require.context('./', true, /\.vue$/);

const modules = modulesFiles.keys().reduce((modules, moduleDir) => {

  const modulePath = moduleDir.replace(/^\.\/(.*)\.\w+$/, '$1')

  const value = modulesFiles(moduleDir);

  // console.log("Article",Article);
  // "cloud/widgets/forms/select/index.vue"
  // components/cloud-tools/plugins/grid-attribute/index.vue

  let data = value.default ? value.default : value;

  let dir = "cloud" + ltrim(moduleDir, ".")

  let _key = md5(dir);

  modules[_key] = data;

  return modules
}, {})

export default modules
